package com.sniff.atp.manage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundGeoOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class RedisManage {
    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    public void delKey(String key){
        redisTemplate.delete(key);
    }

    public String getKey(String key){
        // 使用key获取value
        ValueOperations<String, String> valueOps = redisTemplate.opsForValue();
        String  value = valueOps.get(key);
        return value;
    }
    public void setKey(String key,String value, Long timeout){
        // 使用key设置value
        ValueOperations<String, String> valueOps = redisTemplate.opsForValue();
        valueOps.set(key, value, timeout, TimeUnit.SECONDS);
    }
}
